* Author: Anina Schwarzenbach
* generated October 2014
* last review August 2020

clear
*cd: 
use "../../STATAfiles/S11FR_version4.dta"

*load ADOS
sysdir set PERSONAL "../../../ados"

*******************************************************************************************
*SCAELS FOR FRANCE
******************************************************************************************

*define labels
label define dummylb 0 "no" 1 "yes", replace 
label define scalelb 1 "not true at all" 4 "completely true", replace

******** ******** ******** ******** ******** ******** 
*ATTACHMENT TO MOTHER
* FOR FRANCE: ONLY ONE ITEM

******** ******** ******** ******** ******** ******** 
*COMMITMENT TO SCHOOL

foreach v of var attsch1 attsch2 attsch3 {
	recode `v' (4=1) (3=2) (2=3) (1=4), gen (`v'f)
}

global polyitems  attsch1f attsch2f attsch3f
fre $polyitems

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid >= 2
				replace polypca`var'=. if polyvalid < 2
}


polychoric polypca* /*polychoric correlation matrix*/
display r(sum_w) /*n of cases*/
global N = r(sum_w) /*global macro n of cases*/
matrix r = r(R) /*matrix object*/
factormat r, pf n($N) factors(1) /*factor analysis unidimensional w/o rotation*/
alpha polypca*
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash))

predict  sattsch 
egen zsattsch = std(sattsch) 
drop poly* 	

label var zsattsch "score positive school attitude (higher=better)"

******** ******** ******** ******** ******** ******** 
*PARENTAL MONITORING

/*
global polyitems parmon1 parmon2

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid == 2
				replace polypca`var'=. if polyvalid < 2
				fre polypca`var'				
}



polychoric polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash)) 

predict  sparmon
egen zsparmon = std(sparmon) 
drop poly* 	

label var zsparmon "score parental monitoring / information parents about leisure time / peers (higher=better)"
*/

******** ******** ******** ******** ******** ******** 
*NEIGHBORHOOD

* overview distribution missings
fre nbhd2 nbhd3 nbhd4 nbhd5 nbhd6 

foreach v in nbhd2 nbhd3 nbhd4 nbhd5 nbhd6 {
	recode `v' (99=.)
}

*neighbourhood percpetions
global polyitems nbhd2 nbhd3 nbhd4 nbhd5 nbhd6 

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid >= 3
				replace polypca`var'=. if polyvalid < 3
}

polychoric polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash)) 

predict snbhd1 /*estimation of score*/ 
egen zsnbhd1 = std(snbhd1) /*z-transform*/
drop poly* /*drop temporary variables*/

*neighbourhood incivilities
global polyitems nbhd4 nbhd5 nbhd6

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid == 3
				replace polypca`var'=. if polyvalid < 3
}


polychoric polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash)) 

predict snbhd2  
egen zsnbhd2 = std(snbhd2) 
drop poly* 

label var zsnbhd1 "score neighbourh. perception  (higher=worse)" 
label var zsnbhd2 "score neighbourh. incidvilities  (higher=worse)"

******** ******** ******** ******** ******** ******** 
*DEVIANT ATTITUDES (ATTITUDES FAVORABLE TO DELINQUENCY)
*NEW

foreach v of var attviol1 attviol5 {
	recode `v' (4=1) (3=2) (2=3) (1=4), gen (`v'f)
}

global polyitems  attviol1f attviol2 attviol4 attviol5f

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid >= 3
				replace polypca`var' =. if polyvalid < 3
				fre polypca`var'
				
}

polychoric polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash)) 

predict sattviol 
egen zsattviol = std(sattviol) 
drop poly* 

label var zsattviol "score deviant attitudes (higher=more)"
label define zsattviollb 1 "low" 4 "high"
label val zsattviol zsattviollb

******** ******** ******** ******** ******** ******** 
*POLICE LEGITIMACY
foreach v of var pleg2 pleg5 pleg6 pleg7 {
	recode `v' (4=1) (3=2) (2=3) (1=4), gen(`v'f)
	recode `v'f (99=.)
}

*global attitudes
*all items EXCEPT pleg5f 
global polyitems pleg1 pleg2f pleg3 pleg4 pleg6f pleg7f 
fre $polyitems 

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid >= 4
				replace polypca`var' =. if polyvalid < 4				
}

polychoric polypca* 
*alpha polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash)) 

predict spleg  
egen zspleg = std(spleg) 
drop poly* 

lab var zspleg "score police legitimacy (higher=better)"

corr zspleg age3
spearman zspleg dole1

/*
* fairness 
pleg1: The police protect adolescents
pleg2f: The police disrespect adolescents
pleg7f: The police treat foreigners worse than native people
pleg3: Overall the police can be trusted


*obligation to obey / moral alignement with police
pleg4: One should in any case follow the instructions of the police
pleg6f: If adolescents protest violently and with riots against the police I would join them
pleg5f: Even if having a serious problem, I would never contact the police

*/

capture drop spleg_fair splegr_fair zspleg_fair zspleg_moral spleg_moral splegr_moral

* fairness 
global polyitems pleg1 pleg2f pleg3 pleg7f 
fre $polyitems 

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid >= 3
				replace polypca`var' =. if polyvalid < 3				
}

polychoric polypca* 
*alpha polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash)) 

predict spleg_fair  
egen zspleg_fair = std(spleg_fair) 
drop poly* 

lab var zspleg_fair "score police legitimacy (higher=better) - FAIRNESS"

*obligation to obey

recode pleg4  (99=.)
recode  pleg5f (99=.)
fre pleg4 pleg5f 

egen spleg_obey=rowmean(pleg4 pleg5f)
lab var spleg_obey "mean police legitimacy (higher=better) -  OBLIGATION TO OBEY"

egen zspleg_obey = std(spleg_obey) 

/*
global polyitems  pleg4 pleg5f pleg6f 
fre $polyitems 

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid >= 2
				replace polypca`var' =. if polyvalid < 2				
}


polychoric polypca* 
*alpha polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash)) 
alpha polypca* // 0.5529

predict spleg_obey  
egen zspleg_obey = std(spleg_obey) 
drop poly* 

lab var zspleg_obey "score police legitimacy (higher=better) -  OBLIGATION TO OBEY"
*/

******** ******** ******** ******** ******** ******** 
*** VICARIOUS EXPERIENCES OF POLICE DISRESPECT

foreach v of var vicexp1 vicexp2 {
	recode `v' (99=.)
}


global polyitems vicexp1 vicexp2 vicexp3
fre $polyitems 

egen polyvalid = anycount ($polyitems), values (1/3) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid == 3
				replace polypca`var' =. if polyvalid < 3				
}

polychoric polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash))  

predict svicexpFR  
egen zsvicexpFR = std(svicexpFR) 
drop poly* 

/*
recode svicexp (1/2.0=1) (2.1/3.0=2) (3.1/max=3), gen(vicexp_k)
lab var svicexp "numb. vicarious experience of police disrespect - (1=no, 2=once, 3=often) - cat."
label define svicexplb 1"no" 2"once" 3"often"
label value svicexp svicexplb
*/

lab var zsvicexpFR "score vicarious experiences (higher=worse) - FRANCE"


******** ******** ******** ******** ******** ******** 
***POLICE BEHAVIOR

capture drop pbeh1f pbeh2f spbeh

foreach v in pbeh1 pbeh2 {
	recode `v'(4=1) (3=2) (2=3) (1=4), gen (`v'f)
	label define pbehlb 1 "no, not true at all" 2 "no, rather untrue" 3 "yes, rather true" 4 "yes, fully true", replace
	label value `v'f pbehlb
}

global polyitems pbeh1f pbeh2f pbeh3 pbeh4
*global polyitems  pbeh2f pbeh3 pbeh4

fre $polyitems if lastcont3 > 0 & lastcont3 !=99
alpha $polyitems

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid


foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid >= 3
				replace polypca`var' =. if polyvalid < 3				
}

polychoric polypca* 
display r(sum_w) 
global N = r(sum_w)
matrix r = r(R) 
factormat r, pf n($N) factors(1) 
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash))  
alpha polypca* //0.6937

predict spbeh 
egen zspbeh = std(spbeh) 
drop poly* 

label var zspbeh "score police behavior 1-4 (higher=better)"

******** ******** ******** ******** ******** ******** 
* DELINQUENCY OF PEERS
*egen speerdel=rowmean(peerdel2 peerdel5 peerdel6 peerdel7)
*capture drop speerdel

global polyitems  peerdel2 peerdel5 peerdel6 peerdel7
fre $polyitems

egen polyvalid = anycount ($polyitems), values (1/4) /*count nonmissing*/
fre polyvalid

foreach var in $polyitems{
                gen polypca`var' = `var' 
                quietly sum `var', detail
                replace polypca`var' = r(p50) if `var' ==. & polyvalid >= 3
				replace polypca`var'=. if polyvalid < 3
}

polychoric polypca* /*polychoric correlation matrix*/
display r(sum_w) /*n of cases*/
global N = r(sum_w) /*global macro n of cases*/
matrix r = r(R) /*matrix object*/
factormat r, pf n($N) factors(1) /*factor analysis unidimensional w/o rotation*/
*screeplot, mean meanlopts(lwidth(thin) lpattern(dash))
alpha polypca* // 0.7479

predict speerdel 
egen zspeerdel = std(speerdel) 
drop poly* 


******************************** STANDARDIZATION OF SCALES (NON-FACTORS)  ********************************
* rescaling variable to the max = 4
quietly sum spleg
gen splegr = spleg*(4/r(max))
sum splegr

quietly sum spleg_fair
gen splegr_fair = spleg_fair*(4/r(max))
sum splegr_fair

quietly sum spleg_obey
gen splegr_obey = spleg_obey*(4/r(max))
sum splegr_obey 

quietly sum sattviol
gen sattviolr = sattviol*(4/r(max))
sum sattviolr

quietly sum spbeh
gen spbehr = spbeh*(4/r(max))
sum spbehr

quietly sum svicexp
gen svicexpr = svicexp*(4/r(max))
sum svicexpr

*soci-demographics
quietly egen zage1 = std(age1)

*parental monitoring
egen zsparmon = std(sparmon) 

*victimization 
egen zvic_sum = std(vic_sum)

*delinquency
egen zsrd_sum = std(srd_sum)

* peer delinquency
egen zpeerdel_sum = std(peerdel_sum)
*egen zspeerdel = std(speerdel) 

*police contact
egen zpcont_sum= std(pcont_sum)
egen zpconta_sum= std(pconta_sum)
egen zpcontb_sum= std(pcontb_sum)
egen zpcontc_sum= std(pcontc_sum)

*national identity
egen znatident1 = std(natident1)
egen znatident2 = std(natident2)

*vicarous experiences
egen zsvicexp = std(svicexp)

*religion
egen zrelig1 = std(relig1)


saveold "../../STATAfiles/S11FR_version4scales.dta", replace





